import router from "./router";
import { useCounterStore } from "src/store/userLoginStore";
import { message } from "ant-design-vue";

// 全局权限校验

router.beforeEach(async (to, from, next) => {
  const loginUserStore = useCounterStore();
  const loginUser = await loginUserStore.loginUser;
  const toUrl = to.fullPath;
  // if(toUrl === "/admin/userManage") {
  // // 自己写判断
  // }
  if (toUrl.startsWith("/admin")) {
    if (!loginUser || loginUser.userRole !== 1) {
      message.error("没有权限");
      next("/user/login?redirect=${to.fullPath}");
      return;
    }
  }
  next();
});
